package com.thingple.otg;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.nfc.Tag;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.thingple.nfc.NfcActivity;
import com.thingple.reader.ReaderActivity;
import com.thingple.usb.LimitedClick;
import com.thingple.usb.MonitorActivity;
import com.thingple.usb.manager.UsbManagerWrapper;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = MainActivity.class.getName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        init();
//        root();
        try {
            UsbManagerWrapper.init(this.getApplicationContext());
        } catch (Exception e) {
            Log.d(TAG, "USB Manager没有打开:" + e.getMessage());
        }
        initUI();
    }

    private void initUI() {
        Button readerBtn = findViewById(R.id.btn_reader);
        readerBtn.setOnClickListener(new LimitedClick(300, view -> openReader()));
    }

    private void openReader() {
        Intent intent = new Intent();
        intent.setClass(this, ReaderActivity.class);
        startActivity(intent);
    }


    public void openUsb(View view) {
        Intent intent = new Intent();
        intent.setClass(this, MonitorActivity.class);
        startActivity(intent);
//        finish();
    }

    public void openNfc(View view) {
        Intent intent = new Intent();
        intent.setClass(this, NfcActivity.class);
        startActivity(intent);
//        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}